# -*- coding:utf-8 -*-
# author: helili
# @Time: 2019/12/21 下午5:19

from selenium import webdriver
from selenium.webdriver import ChromeOptions
import os
import sys

PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)


def init_headless_driver():
    global chromedriver
    option = ChromeOptions()
    # *****************规避被监测***********************
    option.add_experimental_option('excludeSwitches', ['enable-automation'])
    # 无头浏览器设置（*********增加爬取效率）
    # option.add_argument('--headless')
    # chromedriver地址，根据系统区分需要用哪个文件
    if sys.platform == "darwin":
        chromedriver = "/Users/pengkaifeng/BrowserDrivers/chromedriver"
    elif sys.platform == "win32":
        chromedriver = PATH("../driver/chromedriver.exe")
    elif sys.platform == "linux2":
        chromedriver = PATH("../exe/driver_Linux/chromedriver.exe")
    # 初始化一个driver
    driver = webdriver.Chrome(chromedriver, options=option)
    driver.set_window_size(1400, 850)
    driver.implicitly_wait(10)
    print("---*引入driver---*")
    return driver


def init_driver():
    global chromedriver
    option = ChromeOptions()
    # *****************规避被监测***********************
    option.add_experimental_option('excludeSwitches', ['enable-automation'])
    # option.add_argument('--headless')
    # chromedriver地址，根据系统区分需要用哪个文件
    if sys.platform == "darwin":
        chromedriver = PATH("../exe/chromedriver")
    elif sys.platform == "win32":
        chromedriver = PATH("../exe/chromedriver.exe")
    elif sys.platform == "linux2":
        chromedriver = PATH("../exe/driver_Linux/chromedriver.exe")
    # 初始化一个driver
    driver = webdriver.Chrome(chromedriver, options=option)
    driver.set_window_size(1400, 850)
    driver.implicitly_wait(10)
    print("---*引入driver---*")
    return driver
